<?php
foreach(glob(__DIR__.'/*.php') as $f){
  require_once($f);
}

function xpath_instance($id){
  $xp = $GLOBALS["currentXP"];
  foreach($xp->document->getElementsByTagName("instance") as $i) {
    if($i->getAttribute("id")==$id) {
      return $xp->getFirstElement($i);
    }
  }
  return null;
}

function xpath_resource($id){
  $xp = $GLOBALS["currentXP"];
  foreach($xp->document->getElementsByTagName("instance") as $i) {
    if($i->getAttribute("id")==$id) {
      return $xp->getFirstElement($xp->getFirstElement($i));
    }
  }
  return null;
}

function xpath_encode($value){
  return $GLOBALS["currentXP"]->document->createTextNode('$&'.serialize($value));
}

function xpath_debug($val){
  var_dump($val);
  return $val;
}
